{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2023-12-27T14:59:41.302989800Z",
     "start_time": "2023-12-27T14:59:40.382169Z"
    }
   },
   "outputs": [],
   "source": [
    "import requests\n",
    "from lxml import etree\n",
    "\n",
    "headers = {\n",
    "    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0'\n",
    "}\n",
    "\n",
    "url = 'http://bang.dangdang.com/books/newhotsales/01.00.00.00.00.00-month-2023-1-1-1'\n",
    "response = requests.get(url,headers=headers)\n",
    "html = etree.HTML(response.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['1.'], ['钱从哪里来4：岛链化经济（著名金融学者香帅年度力作，探寻“钱从哪里来”的答案，帮你找到安全、向上的财富之路）'], ['27491条评论'], ['99.9%推荐'], ['香帅 著; 得到图书 出品', '香帅', '2022-12-01', '新星出版社'], ['¥52.00'], ['¥69.00'], ['7.5折']]\n",
      "[['2.'], ['变量5：在中国这艘大船上（翻开这本书，让我们同舟共济。“变量”第五年，陪你在不确定中寻找确定）'], ['21228条评论'], ['99.8%推荐'], ['何帆 著; 得到图书 出品', '何帆', '2022-12-29', '新星出版社'], ['¥52.00'], ['¥69.00'], ['7.5折']]\n",
      "[['3.'], ['启发（罗胖罗振宇的新书来啦！一本帮你打开思路的启发词典，每当千钧一发，就来启发一下。）'], ['15294条评论'], ['100%推荐'], ['罗振宇 著; 得到图书 出品', '罗振宇', '2022-12-08', '新星出版社'], ['¥79.00'], ['¥99.00'], ['8.0折']]\n",
      "[['4.'], ['再见绘梨 【赠观影时光纸骰子+绘梨印象拼图卡】藤本树著 简体中文版未删减 电锯人 蓦然回首同作者 漫画书中信出版'], ['45862条评论'], ['100%推荐'], ['藤本树 吴曦', '藤本树', '2023-01-15', '中信出版社'], ['¥27.80'], ['¥35.00'], ['7.9折']]\n",
      "[['5.'], ['金线（麦肯锡真正在用的管理工具。冯唐倾囊相授成事学修炼方法。）'], ['47740条评论'], ['100%推荐'], ['冯唐，果麦文化 出品', '冯唐', '2022-11-01', '广东经济出版社有限公司'], ['¥29.00', '¥39.80'], ['¥58.00'], ['5.0折']]\n",
      "[['6.'], ['什么样的爱值得勇敢一次'], ['15129条评论'], ['100%推荐'], ['沈奕斐', '沈奕斐', '2022-12-01', '江苏凤凰文艺出版社'], ['¥45.10', '¥29.90'], ['¥59.80'], ['7.5折']]\n",
      "[['7.'], ['人教版快乐读书吧名著阅读课程化丛书二年级下册套装（七色花+神笔马良+愿望的实现+大头儿子和小头爸爸+一起长大的玩具）共5册'], ['17138条评论'], ['100%推荐'], ['曹文轩、陈先云 主编', '曹文轩', '2019-01-01', '人民教育出版社'], ['¥60.00'], ['¥80.00'], ['7.5折']]\n",
      "[['8.'], ['西西家族成长日记.我会爱自己（套装4册）给孩子的情商教育性格培养绘本睡前亲子读物和孙俪一起呵护成长'], ['44615条评论'], ['100%推荐'], ['孙俪;小博集出品', '孙俪', '2022-11-01', '湖南少年儿童出版社'], ['¥84.00', '¥120.99'], ['¥168.00'], ['5.0折']]\n",
      "[['9.'], ['精进日志：高效能人士的管理工具（印签版）'], ['3725条评论'], ['99.7%推荐'], ['张丽俊 著，磨铁文化 出品', '张丽俊', '2023-03-01', '民主与建设出版社'], ['¥63.30'], ['¥88.00'], ['7.2折']]\n",
      "[['10.'], ['深海大饭店的传说【赠印绘签+海獭有财贴纸+南河求赞立卡】电影《深海》官方授权，银幕同款原创绘本！'], ['13349条评论'], ['100%推荐'], ['南河  著绘', '南河', '2023-01-22', '中信出版社'], ['¥126.00'], ['¥168.00'], ['7.5折']]\n",
      "[['11.'], ['斑马项链（无敌侦探普雷舍丝系列 2023年百班千人寒假书单 三年级推荐阅读）'], ['7478条评论'], ['100%推荐'], ['【英】亚历山大・麦考・史密斯/著 【英】伊恩・麦金托什 绘', '亚历山大・麦考・史密斯', '2022-11-01', '青岛出版社'], ['¥14.00'], ['¥28.00'], ['5.0折']]\n",
      "[['12.'], ['流浪地球・彩插版（2023全新彩插升级版，含《三体》震撼情节！）'], ['23472条评论'], ['100%推荐'], ['刘慈欣 著,博集天卷 出品', '刘慈欣', '2022-12-31', '中国科学技术出版社'], ['¥22.50'], ['¥45.00'], ['5.0折']]\n",
      "[['13.'], ['土地婆婆和阿菊阿宝（2023年百班千人寒假书单 三年级推荐阅读）'], ['9118条评论'], ['100%推荐'], ['张秋生', '张秋生', '2022-05-01', '春风文艺出版社'], ['¥11.50', '¥9.99'], ['¥23.00'], ['5.0折']]\n",
      "[['14.'], ['无字书图书馆（2023年百班千人寒假书单 三年级推荐阅读）'], ['35617条评论'], ['100%推荐'], ['[西]霍尔迪・塞拉・依・法布拉', '霍尔迪・塞拉・依・法布拉', '2022-12-01', '新蕾出版社'], ['¥12.00'], ['¥24.00'], ['5.0折']]\n",
      "[['15.'], ['铁路边的孩子们（2023年百班千人寒假书单 四年级推荐阅读）'], ['11365条评论'], ['99.9%推荐'], ['伊迪斯・内斯比特 著；任溶溶 译', '伊迪斯・内斯比特', '2018-01-01', '上海译文出版社'], ['¥9.50'], ['¥19.00'], ['5.0折']]\n",
      "[['16.'], ['作业机器的秘密（2023年百班千人寒假书单 四年级推荐阅读）'], ['11474条评论'], ['100%推荐'], ['[美国]丹・古特曼 著 筱舟 译', '丹・古特曼', '2022-06-01', '译林出版社'], ['¥14.50'], ['¥29.00'], ['5.0折']]\n",
      "[['17.'], ['在900年前航拍中国（2023年百班千人寒假书单 四年级推荐阅读）'], ['9320条评论'], ['100%推荐'], ['朋朋哥哥', '朋朋哥哥', '2022-12-01', '新蕾出版社'], ['¥22.40'], ['¥32.00'], ['7.0折']]\n",
      "[['18.'], ['经典常谈 朱自清著八年级下册语文教材名著导读推荐阅读书目 适合学生自主阅读的课外阅读读本 一部讲述中国传统经典文化的著作'], ['36212条评论'], ['100%推荐'], ['朱自清', '朱自清', '2023-01-01', '南方出版社'], ['¥20.10'], ['¥26.80'], ['7.5折']]\n",
      "[['19.'], ['熊猫小四（2023年百班千人寒假书单 四年级推荐阅读）'], ['13189条评论'], ['100%推荐'], ['叶广芩 著', '叶广芩', '2022-10-06', '北京少年儿童出版社'], ['¥29.00'], ['¥42.00'], ['6.9折']]\n",
      "[['20.'], ['惊险旅途（2023年百班千人寒假书单 三年级推荐阅读）'], ['7211条评论'], ['100%推荐'], ['曾有情', '曾有情', '2022-12-01', '天天出版社有限责任公司'], ['¥14.00'], ['¥28.00'], ['5.0折']]\n"
     ]
    }
   ],
   "source": [
    "li = html.xpath('/html/body/div[@class=\"bang_wrapper\"]/div[@class=\"bang_content\"]/div[@class=\"bang_list_box\"]/ul/li')\n",
    "for i in li:\n",
    "    rank = i.xpath('./div[1]/text()')\n",
    "    name = i.xpath('./div[@class=\"name\"]/a/@title')\n",
    "    comment_count = i.xpath('./div[@class=\"star\"]/a/text()')\n",
    "    recommend_percent = i.xpath('./div[@class=\"star\"]/span[@class=\"tuijian\"]/text()')\n",
    "    publisher_info_div = i.xpath('./div[@class=\"publisher_info\"]')\n",
    "    publisher_info = [info for div in publisher_info_div for info in div.xpath('./a[1]/@title|./a[1]/text()|./span/text()')]\n",
    "    price_n = i.xpath('./div[@class=\"price\"]/p/span[@class=\"price_n\"]/text()')\n",
    "    price_r = i.xpath('./div[@class=\"price\"]/p/span[@class=\"price_r\"]/text()')\n",
    "    price_s = i.xpath('./div[@class=\"price\"]/p/span[@class=\"price_s\"]/text()')\n",
    "    print([rank,name,comment_count,recommend_percent,publisher_info,price_n,price_r,price_s])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-27T15:29:44.404642900Z",
     "start_time": "2023-12-27T15:29:44.396643100Z"
    }
   },
   "id": "a3d9385578897f2f"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
